/**
 * websocket类，用于websocket连接，通信
 * 
 */
;cmedit.websocket = (function ($, window, document) {
        return {
        	stompClient: null,
            connect:function(way,callback){
            	//当使用sockJs的时候只能使用http访问;如http://10.10.0.115:9010/gateway/endpointAric,使用new Websocket()只能使用ws://
				var socket = new SockJS(window.location.protocol + '//' + window.location.host+'/gateway/endpointAric'); //连接SockJS的endpoint名称为"endpointWisely"
				stompClient = Stomp.over(socket);//使用STMOP子协议的WebSocket客户端
				stompClient.connect({},function(frame){//连接WebSocket服务端
				console.log('Connected:' + frame);
				//通过stompClient.subscribe订阅/topic/news 目标(某个页面tv_list或者tv_edit)发送的消息,这个是在控制器的@SentTo中定义的
				stompClient.subscribe('/topic/webpage/'+way,function(response){
						callback(response.body);
					});
				});
			},
			
			//断开连接
			disconnect:function(){
				if(stompClient != null) {
					stompClient.disconnect();
				}
				console.log("Disconnected");
			},
			
			/**
			 * 发送消息到后端
			 * way:消息路由mapping地址
			 * msg:消息实体
			 */
			sendMessage:function(way,msg){
				stompClient.send(way,{},msg);//JSON.stringify()
			}
        };
    })(jQuery, window, document);
//调用初始化方法
//$(dynews.websocket.init());